function flat(l){
    let ret=new Array();
    for(let i of l){
        console.log(typeof i);
        if(typeof i == "number"){
            ret.push(i);
        }
        else{
            for(let j of flat(Array.from(i))){
                ret.push(j);
            }
        }
    }
    return ret;
}

var NestedIterator = function(nestedList) {
    this.list=flat(nestedList);
    console.log(this.list)
    this.index=0;
};


/**
 * @this NestedIterator
 * @returns {boolean}
 */
NestedIterator.prototype.hasNext = function() {
    return this.index<this.list.length;
};

/**
 * @this NestedIterator
 * @returns {integer}
 */
NestedIterator.prototype.next = function() {
    this.index++;
    return this.list[this.index-1];
};

var a=new NestedIterator([[1,1],2,[1,1]]);


while(a.hasNext()){
    console.log(a.next());
}